package handler

import (
	"context"
	"thriftbam/models"
	"thriftbam/service"

	"github.com/cloudwego/hertz/pkg/app"
	"github.com/cloudwego/hertz/pkg/protocol/consts"
)

type Response struct {
	StatusCode int32
	StatusMsg  string
}

func AnalyzeIDL(c context.Context, ctx *app.RequestContext) {
	var req models.UserRequest
	err := ctx.BindAndValidate(&req)
	if err != nil {
		ctx.JSON(consts.StatusInternalServerError, Response{
			StatusCode: 500,
			StatusMsg:  "服务器无法处理请求",
		})
		return
	}
	_, err = service.NewThriftFileService(c, ctx).AnalyzeIDL(&req)
	if err != nil {
		ctx.JSON(consts.StatusInternalServerError, Response{
			StatusCode: 500,
			StatusMsg:  "服务器无法处理请求",
		})
		return
	}

	ctx.JSON(consts.StatusOK, Response{
		StatusCode: 200,
		StatusMsg:  "请求成功",
	})
}
